<template>
  <div style="width:100%;height:100%">
    <v-chart :options="option" :initOptions="initOptions" :theme="theme" autoresize />
  </div>
</template>
<script>

export default {
  name: 'chart',
  props: ['getDetail'],
  mounted () {
  },
  data () {
    return {
      initOptions: { renderer: 'canvas' },
      theme: 'default'
    }
  },
  methods: {
  },
  computed: {
    getSeries () {
      var series = []
      series.push({
        type: 'bar',
        name: this.getDetail.sheetData[0][1],
        encode: {
          x: 0,
          y: 1
        },
        ...this.getDetail.simpleBar
      })
      series.push({
        type: 'line',
        name: this.getDetail.sheetData[0][2],
        yAxisIndex: 1,
        encode: {
          x: 0,
          y: 2
        },
        ...this.getDetail.simpleLine
      })
      return series
    },
    option () {
      return {
        animation: this.getDetail.animation,
        title: this.getDetail.title,
        legend: this.getDetail.legend,
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
              type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        dataset: {
          source: this.getDetail.sheetData
        },
        xAxis: this.getDetail.xAxis,
        yAxis: [{
          ...this.getDetail.yAxis,
          type: 'value',
          name: this.getDetail.sheetData[0][1],
          min: 0,
          position: 'left',
          axisLabel: {
              formatter: '{value}'
          }
          },
          {
            ...this.getDetail.yAxis,
           type: 'value',
           name: this.getDetail.sheetData[0][2],
           min: 0,
           position: 'right',
           axisLabel: {
               formatter: '{value}'
           }
          }
        ],
        series: this.getSeries,
        color: this.getDetail.color[this.getDetail.color.option],
        grid: this.getDetail.grid,
        label: this.getDetail.label,
        itemStyle: this.getDetail.itemStyle,
        emphasis: this.getDetail.emphasis,
        backgroundColor: this.getDetail.backgroundColor[this.getDetail.backgroundColor.option]
      }
    }
  }
}
</script>
<style scoped>
  .echarts {
    width: 100%;
    height: 100%;
  }
</style>
<style>

</style>
